package com.entor.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;

public class HighChartUtil {
	
	public static String getPie(String title,List<Map<String,Object>> list){
		StringBuffer sb = new StringBuffer();
		sb.append("{");
		sb.append("\"chart\": {\"plotBackgroundColor\": null,\"plotBorderWidth\": null,\"plotShadow\": false,\"type\": \"pie\"},");
		sb.append("\"title\": {\"text\": \""+title+"\"},");
		sb.append("\"tooltip\": {\"pointFormat\": \"{series.name}: <b>{point.percentage:.1f}%</b>\"},");
		sb.append("\"plotOptions\": {\"pie\": {\"allowPointSelect\": true,\"cursor\": \"pointer\",\"dataLabels\": { \"enabled\": true,\"format\": \"<b>{point.name}</b>: {point.percentage:.1f} %\",\"style\": {\"color\": \"(Highcharts.theme && Highcharts.theme.contrastTextColor) || black\"}}}},");
		sb.append("\"series\": [{\"name\": \"占比\",\"colorByPoint\": true,\"data\": "+JSON.toJSONString(list)+"}]");
		sb.append("}");
		return sb.toString();
	}

	public static String getColumn(String title,String subtitle,String y,
			String x[],List<Map<String, Object>> list,String type){
		StringBuffer sb = new StringBuffer();
		
		
		sb.append("{");
		sb.append("\"chart\": {\"type\": \""+type+"\"},");
		sb.append("\"title\": {\"text\": \""+title+"\"},");
		sb.append("\"subtitle\": {\"text\": \""+subtitle+"\"},");
		sb.append("\"xAxis\": {\"categories\": "+JSON.toJSONString(x)+",\"crosshair\": true},");
		sb.append("\"yAxis\": {\"min\": 0,\"title\": {\"text\": \""+y+"\"}},");
		
		// head + 每个 point + footer 拼接成完整的 table
		sb.append("\"tooltip\": {\"headerFormat\": \"<span style='font-size:10px'>{point.key}</span><table>\",\"pointFormat\": \"<tr><td style='color:{series.color};padding:0'>{series.name}: </td><td style='padding:0'><b>{point.y:.1f} mm</b></td></tr>\",\"footerFormat\": \"</table>\",\"shared\": true,\"useHTML\": true},");
		
		sb.append("\"plotOptions\": {\"column\": {\"borderWidth\": 0}},");
		sb.append("\"series\": "+JSON.toJSONString(list)+"");
		
    		
		sb.append("}");
		
		
		
		return sb.toString();
	}
}
/*
    
    
    
    
   
    tooltip: {
        // head + 每个 point + footer 拼接成完整的 table
        headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
        pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
        '<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>',
        footerFormat: '</table>',
        shared: true,
        useHTML: true
    },
    
    
*/